<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>guess number 猜数字</title>
  </head>
  
  <body>
    <form action="GuessServlet" method="post">
    	<label>请输入1-50的数字：</label><input type="text" name="number" />
    	<%
    		//获得转发来的结果和猜的次数
    		Object data=request.getAttribute("count");
    		int count=0;
    		if(data!=null){
    			count=(Integer)data;
    		}
    	%>
    	<input type="hidden" name="count" value="<%=count %>" />
    	<%
    		String result=(String)session.getAttribute("result");
    		if("b".equals(result)){
    			//大了
		    	%>
		    		<p>大了！</p>
   					<p>这是您第<%=count %>次猜拳，您共有5次机会！</p>
		    		<button type="submit">猜一猜</button>
		    	<%
    		}else if("s".equals(result)){
    			//小了

		    	%>
		    		<p>小了！</p>
   					<p>这是您第<%=count %>次猜拳，您共有5次机会！</p>	
		    		<button type="submit">猜一猜</button>
		    	<%
    		}else if("l".equals(result)){
    			//输了
				session.removeAttribute("result");
    	    	%>
    	    		<p>抱歉，您已经输了！</p>
    	    		<a href="demo06_guess.jsp"><button type="button">重新开始！</button></a>
    	    	<%
    		}else if("w".equals(result)){
    			//赢了
				session.removeAttribute("result");
    	    	%>
		    		<p>恭喜您，赢了！</p>
    	    		<a href="demo06_guess.jsp"><button type="button">重新开始！</button></a>
	    		<%
    		}else{
    	    	%>
    	    		<button type="submit">猜一猜</button>
	    		<%
    		}
    	%>
    	
    </form>
    <div>
    </div>
  </body>
</html>
